<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
</head>
<body>
<script>

description("This tests the constructor for the CompositionEvent DOM class.");

var testObject = {nyannyan: 123};

// No initializer is passed.
shouldBe("new CompositionEvent('eventType').bubbles", "false");
shouldBe("new CompositionEvent('eventType').cancelable", "false");
shouldBe("new CompositionEvent('eventType').view", "null");
shouldBe("new CompositionEvent('eventType').detail", "0");
shouldBeEqualToString("new CompositionEvent('eventType').data", "");

// bubbles is passed.
shouldBe("new CompositionEvent('eventType', { bubbles: false }).bubbles", "false");
shouldBe("new CompositionEvent('eventType', { bubbles: true }).bubbles", "true");

// cancelable is passed.
shouldBe("new CompositionEvent('eventType', { cancelable: false }).cancelable", "false");
shouldBe("new CompositionEvent('eventType', { cancelable: true }).cancelable", "true");

// view is passed.
// Window objects.
shouldBe("new CompositionEvent('eventType', { view: window }).view", "window");
shouldBe("new CompositionEvent('eventType', { view: this }).view", "this");

// Non-window objects.
shouldThrow("new CompositionEvent('eventType', { view: testObject }).view");
shouldThrow("new CompositionEvent('eventType', { view: document }).view");
shouldBe("new CompositionEvent('eventType', { view: undefined }).view", "null");
shouldBe("new CompositionEvent('eventType', { view: null }).view", "null");
shouldThrow("new CompositionEvent('eventType', { view: false }).view");
shouldThrow("new CompositionEvent('eventType', { view: true }).view");
shouldThrow("new CompositionEvent('eventType', { view: '' }).view");
shouldThrow("new CompositionEvent('eventType', { view: 'chocolate' }).view");
shouldThrow("new CompositionEvent('eventType', { view: 12345 }).view");
shouldThrow("new CompositionEvent('eventType', { view: 18446744073709551615 }).view");
shouldThrow("new CompositionEvent('eventType', { view: NaN }).view");
// Note that valueOf() is not called, when the left hand side is evaluated.
shouldThrow("new CompositionEvent('eventType', { view: {valueOf: function () { return window; } } }).view == window");
shouldBe("new CompositionEvent('eventType', { get view() { return window; } }).view", "window");
shouldThrow("new CompositionEvent('eventType', { get view() { return 123; } }).view");
shouldThrow("new CompositionEvent('eventType', { get view() { throw 'CompositionEvent Error'; } })");

// data is passed.
// Strings.
shouldBeEqualToString("new CompositionEvent('eventType', { data: 'koakuma' }).data", "koakuma");
shouldBeEqualToString("new CompositionEvent('eventType', { data: '' }).data", "");

// Non-strings.
shouldBeEqualToString("new CompositionEvent('eventType', { data: undefined }).data", "");
shouldBeEqualToString("new CompositionEvent('eventType', { data: null }).data", "null");
shouldBeEqualToString("new CompositionEvent('eventType', { data: false }).data", "false");
shouldBeEqualToString("new CompositionEvent('eventType', { data: true }).data", "true");
shouldBeEqualToString("new CompositionEvent('eventType', { data: 12345 }).data", "12345");
shouldBeEqualToString("new CompositionEvent('eventType', { data: 18446744073709551615 }).data", "18446744073709552000");
shouldBeEqualToString("new CompositionEvent('eventType', { data: NaN }).data", "NaN");
shouldBeEqualToString("new CompositionEvent('eventType', { data: [] }).data", "");
shouldBeEqualToString("new CompositionEvent('eventType', { data: [1, 2, 3] }).data", "1,2,3");
shouldBeEqualToString("new CompositionEvent('eventType', { data: {koakuma: 12345} }).data", "[object Object]");
shouldBeEqualToString("new CompositionEvent('eventType', { data: {valueOf: function () { return 'koakuma'; } } }).data", "[object Object]");

// All initializers are passed.
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).bubbles", "true");
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).cancelable", "true");
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).view", "window");
shouldBe("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).detail", "111");
shouldBeEqualToString("new CompositionEvent('eventType', { bubbles: true, cancelable: true, view: window, detail: 111, data: 'koakuma' }).data", "koakuma");
</script>
</body>
</html>
